package com.org.gameloft.GLIDER.IDE;

import com.org.gameloft.GLIDER.common.GLIDEROptions;
import com.org.gameloft.GLIDER.util.Util;

import javax.swing.*;
import java.util.HashMap;
import java.awt.*;

/**
 * Created by Claudiu-Florin FILIMON
 * Date: Aug 7, 2007
 * Time: 5:49:05 PM
 * Revision: 0
 */
public class ActionManager
{
    private static ActionManager actionManager=null;
    private HashMap actionsMap;

    private ActionManager()
    {
        actionsMap = new HashMap();
    }
    
    public static ActionManager getActionManager()
    {
        if (actionManager==null)
            actionManager = new ActionManager();
        return actionManager;
    }

    public void populateMenu(JMenuBar menuBar)
    {
        menuBar.removeAll();
    }

    public void populateToolbar(JToolBar toolBar)
    {
        int n = GLIDEROptions.getProperty(GLIDEROptions.TOOLBAR_ITEM_COUNT, 0);
        toolBar.removeAll();
        toolBar.add(new JButton("1"));

        for (int i=0;i<n;i++)
        {
            String v = GLIDEROptions.getProperty(GLIDEROptions.TOOLBAR_ITEM_I+ Util.formatInt(i,3), null);
            if (v != null)
            {
                if (v.equals("SEPARATOR"))
                {
                    toolBar.add(new JLabel(" | "));
                }
                else
                {
                    GLIDERAction ga = getAction(v);
                    if (ga != null)
                    {
                    }
                }
            }
        }
        toolBar.add(new JButton("2"));

    }

    public void addAction(GLIDERAction action)
    {
        actionsMap.put(action.getName(), action);
    }

    public GLIDERAction getAction(String name)
    {
        return (GLIDERAction) actionsMap.get(name);
    }

    public void removeAction(String name)
    {
        actionsMap.remove(name);
    }
}
